//
//  AppDelegate.m
//  ScalperMerchant
//
//  Created by 王云 on 2017/9/29.
//  Copyright © 2017年 WY. All rights reserved.
//更改了JTNav的源码
//  关于我们web有问题  
#import "AppDelegate.h"
#import "HomeController.h"
//#import "WXApi.h"
#import "ZYOpenURLTool.h"
#import "FirstViewController.h"
#import "WXApi.h"
#import "ZYNewfeatureViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self loadBaseData];
    
    return YES;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    
    SCUser *user = [SCUserTool loadInfo];
    [SCTool currentVersion:^(BOOL isNew) {
        if (isNew) {
            
            [self.window setRootViewController:[[ZYNewfeatureViewController alloc]init]];
        }else{
            if (user.isLogin && ![user.joinin_state isEqualToString:@"0"]) {
                self.window.rootViewController = [[JTNavigationController alloc] initWithRootViewController:[[HomeController alloc] init]];
            }else{
                JTNavigationController *nav = [[JTNavigationController alloc]initWithRootViewController:[[FirstViewController alloc]init]];
                [self.window setRootViewController:nav];
            }
        }
    }];
    [self.window makeKeyAndVisible];

    [self initializePlat:application launchOptions:launchOptions];

    return YES;
}
#pragma mark  基础数据
- (void)loadBaseData
{
    [[AMapServices sharedServices] setEnableHTTPS:YES];
    [AMapServices sharedServices].apiKey = SCDKlbsKey;
    
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    [SCConfigTool getBaseData];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    
    [[UMSocialManager defaultManager] handleOpenURL:url];
    return [ZYOpenURLTool openURL:url];
    
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    
    [[UMSocialManager defaultManager] handleOpenURL:url];
    return [ZYOpenURLTool openURL:url];
}

#pragma mark   配置数据
- (void)initializePlat:(UIApplication *)application
         launchOptions:(NSDictionary *)launchOptions{
    
    //微信
     [WXApi registerApp:kSDKWeiXinAppKey withDescription:kSDKWeiXinBundleID];
    //统计
    
     UMConfigInstance.appKey = SCYMAPPKey;
     [MobClick setAppVersion:XcodeAppVersion];
     [MobClick startWithConfigure:UMConfigInstance];
     
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;

    //    友盟
    [[UMSocialManager defaultManager] openLog:YES];
    
    [[UMSocialManager defaultManager] setUmSocialAppkey:SCYMAPPKey];
    
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:kSDKQQAppID  appSecret:kSDKQQAppKey redirectURL:@"http://mobile.umeng.com/social"];
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:kSDKWeiXinAppKey appSecret:kSDKWeiXinAppSecret redirectURL:nil];
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:kSDKSinaAppKey  appSecret:kSDKSinaSecret redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
   
    
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
